﻿using Lufei_CaterBLL;
using Lufei_CaterModel;
using Lufei_CaterUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace ItcastCater
{
    public partial class FrmChangeCategory : Form
    {
        public FrmChangeCategory()
        {
            InitializeComponent();
        }

        UpdateMemmberInfo<CategoryInfo> mi= new UpdateMemmberInfo<CategoryInfo>();
        CategoryInfo ci;

        public void SetValue(object sender,EventArgs e)
        {
            //获取要修改的数据
             mi=e as UpdateMemmberInfo<CategoryInfo>;
            if (mi!=null)
            {
                ci=  mi.obj;
                //给窗体控件赋值
                txtCName.Text = ci.CatName;
                txtCNum.Text = ci.CatNum;
                txtCRemark.Text = ci.Remark;           
            }
        }


        CategoryBLL bll=new CategoryBLL();
        private void btnOk_Click(object sender, EventArgs e)
        {
            //判断运行当时是修改的逻辑还是删除的逻辑
            if (mi.Type==2)
            {
                //删除
                //1.封装对象
                CategoryInfo ci1 = new CategoryInfo();
                ci1.CatName = txtCName.Text;
                ci1.CatNum= txtCNum.Text;
                ci1.Remark = txtCRemark.Text;
                ci1.CatId = ci.CatId;
                //调用业务逻辑层修改方法
                bool isUpdate = bll.UpdateCategory(ci1);
                if (isUpdate)
                {
                    MessageBox.Show("修改成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改失败");
                    this.Close();
                }
            }
            else
            {
                //添加
                //1.封装对象
                CategoryInfo ci1 = new CategoryInfo();
                ci1.CatName = txtCName.Text;
                ci1.CatNum = txtCNum.Text;
                ci1.Remark = txtCRemark.Text;
                ci1.DelFlag = 0;
               // ci1.CatId = ci.CatId;
                bool isInsert=   bll.InsertCategory(ci1);
                if (isInsert)
                {
                    MessageBox.Show("插入成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("插入失败");
                    this.Close();
                }

            }

        }
    }
}
